package zju.ccnt.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zju.ccnt.rest.service.BusinessResourceServiceImpl;

import java.security.Principal;

/**
 * Created by Administartor on 2014/8/18.
 */
@RestController
public class HomeController {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    private BusinessResourceServiceImpl businessResourceService;


    @Autowired
    public HomeController(BusinessResourceServiceImpl businessResourceService
    ){
        this.businessResourceService = businessResourceService;
    }

    @RequestMapping("/home")
    public String home(Authentication authentication) {

        return "home";
    }

    @RequestMapping("/admin")
    @PreAuthorize("hasRole('ADMIN')")
    public String admin() {
        return "admin";
    }

    @RequestMapping("/user")
    @PreAuthorize("hasRole('USER')")
    public String user() {
        return "user";
    }

    @RequestMapping("/login")
    public String login() {
        return "login";
    }

    @RequestMapping("/test_business_user")
    @PreAuthorize("hasRole('BUSINESS')")
    public String businessUser(Authentication authentication, Principal principal) {
        return "business_user";
    }

}

